import axios from 'axios'

export const PurchaseService = class PurchaseService {
    static purchaseService = null
    requestUrl = '/purchase/purchases'

    static getInstance() {
        if (this.purchaseService == null) {
            this.purchaseService = new PurchaseService()
        }
        return this.purchaseService
    }

    /**
     * 根据批次id查询采购详情
     * @param id
     */
    getByBatchesOfInventory(id) {
        return axios.get(`${this.requestUrl}/batchesOfInventory/${id}`)
    }

    /**
     * 分页查询库存
     * @param params
     * @returns {Promise<AxiosResponse<T>>}
     */
    getPage(params) {
        return axios.get(`${this.requestUrl}/page`, {
            params
        })
    }

    /**
     * 更新
     * @param data
     */
    update(data) {
        return axios.put(this.requestUrl, data)
    }

    /**
     * 入库
     * @param purchaseId
     */
    inventory(purchaseId) {
        return axios.get(`${this.requestUrl}/inventory`, {
            params: {
                purchaseId
            }
        })
    }

    /**
     * 根据药品入库
     * @param hmrId
     */
    supplement(hmrId){
        return axios.get(`${this.requestUrl}/inventory/${hmrId}`)
    }
}
